package io.terminus.spzx.manager.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.terminus.spzx.manager.service.SysMenuService;
import io.terminus.spzx.model.entity.system.SysMenu;
import io.terminus.spzx.model.vo.common.Result;
import io.terminus.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lichunlong lcl253137@alibaba-inc.com
 * @desc 系统菜单Controller
 * @date 2024-07-29
 */
@RestController
@Tag(name = "系统菜单接口")
@RequestMapping(value = "/admin/system/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 查询系统菜单列表
     *
     * @return 菜单列表
     */
    @GetMapping("/findNodes")
    public Result<List<SysMenu>> findNodes() {
        List<SysMenu> menuList = sysMenuService.findNodes();

        return Result.build(menuList, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加菜单
     *
     * @param sysMenu 系统菜单
     * @return 添加结果
     */
    @PostMapping("/save")
    public Result<Void> save(@RequestBody SysMenu sysMenu) {
        sysMenuService.save(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改菜单
     *
     * @param sysMenu 系统菜单
     * @return 修改结果
     */
    @PutMapping("/update")
    public Result<Void> update(@RequestBody SysMenu sysMenu) {
        sysMenuService.update(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 删除菜单
     *
     * @param id 菜单ID
     * @return 删除结果
     */
    @DeleteMapping("removeById/{id}")
    public Result<Void> removeById(@PathVariable("id") Long id) {
        sysMenuService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
